package service

import (
	"context"
	"jk-webook/internal/repository"
	"jk-webook/internal/service/sms"
	"jk-webook/internal/service/sms/tencent"
)

type CodeService struct {
	repo   *repository.CodeRepository
	smsSvc sms.Service
}

func NewCodeService(repo *repository.CodeRepository) *CodeService {
	return &CodeService{repo: repo, smsSvc: &tencent.Service{}}
}

func (s *CodeService) Send(ctx context.Context, biz, phone, code string) error {
	err := s.repo.Store(ctx, biz, phone, code)
	if err != nil {
		return err
	}

	err = s.smsSvc.Send(ctx, "biz", []string{}, code)
	//redis有这个验证码 但是用户没收到
	if err != nil {
		//重试 传初始化时候的重试
	}
	return err
}
